import Question from '../../models/questions'

/**
 * 创建一个问题
 * @aibokalv@163.com
 * @DateTime         2016-11-21T12:31:34+0800
 * @param            {[type]}                 ctx [description]
 * @return           {[type]}                     [description]
 */
export async function createQuestion (ctx) {
  const question = new Question(ctx.request.body.question)
  try {
    await question.save()
  } catch (err) {
    ctx.throw(422, err.message)
  }

  const str = question.method1()
  const response = question.toJSON()

  ctx.body = {
    question: response,
    str
  }
}

// 获取所有问题
export async function getQuestions (ctx) {
  const questions = await Question.find()
  ctx.body = { questions }
}

